#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-07-24 5:22 下午
# @Author  : yangdy
# @File    : N-ary Tree Preorder Traversal
# @Software: PyCharmCE
from typing import List


"""
# Definition for a Node.
class Node:
    def __init__(self, val=None, children=None):
        self.val = val
        self.children = children
"""


class Solution:
    def preorder(self, root: 'Node') -> List[int]:
        ans = []

        def dfs(rt):
            if rt:
                ans.append(rt.val)
            else:
                return
            for x in rt.children:
                dfs(x)
        dfs(root)
        return ans
